import pymysql


def insertBook(title, author, cover,
               click_total, click_month, click_week,
               recommend_total, recommend_month, recommend_week,
               word_total, monthticket_total, collect):
    db = pymysql.connect(host='localhost', port=3307, user='root', passwd='123456', db='ciweimao', charset='utf8')

    cursor = db.cursor()

    sql = "INSERT INTO ciweimao.book(title, author, cover," \
          "click_total, click_month, click_week, " \
          "recommend_total, recommend_month, recommend_week, " \
          "word_total, monthticket_total, collect)" \
          " values('%s', '%s', '%s', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i', '%i')" % \
          (title, author, cover,
           click_total, click_month, click_week,
           recommend_total, recommend_month, recommend_week,
           word_total, monthticket_total, collect)

    try:
        # 执行sql语句
        cursor.execute(sql)
        db.commit()
    except:
        print('exception')

    db.close()


if __name__ == '__main__':
    insertBook('shit', 'aa', 'fu', 1, 2, 3, 4, 5, 6, 7, 8, 9)
